<template>
	<view class="confirm_an_order">
		<view class="status_bar" style="background-color: #8D84FF;">
			<!-- 这里是状态栏 -->
		</view>
		<view class="confirm_an_order_title">
			<uni-nav-bar :border="false" color="#fff" background-color="#8D84FF" left-icon="left" fixed title="确认订单"
				@clickLeft="back" />
		</view>
		<view class="confirm_an_order_dizhi">
			<view class="confirm_an_order_box_top">
				<uni-icons class="confirm_an_order_box_top_icons" type="forward" color="#666" size="25"></uni-icons>
				<view @click="showDrawer('showLeft')">
					<view class="confirm_an_order_box_top_DZ" v-if="res.address">
						{{res.address.province}}{{res.address.city}}{{res.address.area}}&nbsp;&nbsp;{{res.address.street}}&nbsp;&nbsp;{{res.address.address}}
					</view>
					<view class="confirm_an_order_box_top_XX" v-if="res.address">
						{{res.address.realname}}&nbsp;&nbsp;{{res.address.mobile}}
					</view>
				</view>

				<view class="WDZ" v-if="!res.address" @click="addorderFun()">
					<view class="WDZ_box">
						<uni-icons type="plusempty"></uni-icons>
					</view>
					添加地址
				</view>
			</view>
		</view>

		<view class="confirm_an_order_detail">
			<view class="confirm_an_order_detail_box" v-for="(item,index) in res.goods">
				<view class="confirm_an_order_detail_box_ left">
					<image :src="item.thumb" mode="widthFix"></image>
				</view>
				<view class="confirm_an_order_detail_box_ center">
					{{item.title}}
				</view>
				<view class="confirm_an_order_detail_box_ right">
					<view style="color: #8D84FF;">{{item.marketprice}}</view>
					<view>x{{item.total}}</view>
				</view>
			</view>
		</view>

		<!-- <view class="confirm_an_order_aggregate">
			<view class="confirm_an_order_aggregate_box">
				<view class="confirm_an_order_aggregate_box_">
					共<span style="color:#8D84FF;">{{res.total}}</span>件商品
				</view>
				<view class="confirm_an_order_aggregate_box_" style="justify-content: space-between;">
					<view class="confirm_an_order_aggregate_box_xy">
						需付：
					</view>
					<view class="confirm_an_order_aggregate_box_money">
						￥{{res.goodsprice}}元
					</view>
				</view>
			</view>
		</view> -->

		<view class="confirm_an_order_leaveAnote">
			<view class="confirm_an_order_leaveAnote_box">
				<view class="confirm_an_order_leaveAnote_box_">
					备注：
				</view>
				<view class="confirm_an_order_leaveAnote_box_">
					<textarea @blur="bindTextAreaBlur" v-model="remark" placeholder="商家留言" auto-height />
				</view>
			</view>
		</view>

		<!-- <view class="confirm_an_order_freight" v-if="res.dispatch_price">
			<view class="confirm_an_order_freight_box">
				<view>运费</view>
				<view>{{res.dispatch_price}}</view>
			</view>
		</view> -->

		<!-- <view class="confirm_an_order_freight">
			<view class="confirm_an_order_freight_box">
				<view>商品小计</view>
				<view style="color: #8D84FF;">￥{{res.realprice}}</view>
			</view>
		</view> -->

		<view class="confirm_an_order_bottom_" style="height: 100rpx;"></view>
		<view class="confirm_an_order_bottom">
			<view>需付：{{res.realprice}}</view>
			<view class="confirm_an_order_bottom_an" @click="order_create_submitFun()">
				立即支付
			</view>
		</view>



		<uni-drawer ref="showLeft" mode="right" :width="250" @change="change($event,'showLeft')">
			<view class="close">
				<view class="status_bar">
					<!-- 这里是状态栏 -->
				</view>
				<view class="close_box">
					<view class="close_item" v-for="(item,index) in orderList" :key="index" @click="select(item.id)">
						<view class="close_item_xx">
							<view class="close_item_xx_name">
								{{item.realname}}
							</view>
							<view class="close_item_xx_mobile">
								{{item.mobile}}
							</view>
						</view>
						<view class="close_item_order">
							<view class="close_item_order_top">
								{{item.province}}&nbsp;{{item.city}}&nbsp;{{item.area}}
							</view>
							<view class="close_item_order_bottom">
								{{item.street}}&nbsp;{{item.address}}
							</view>
						</view>
					</view>
				</view>
				<view class="close_bottom" @click="addorderFun()" v-if="orderList.length <= 2">
					新增收货地址
				</view>
			</view>
		</uni-drawer>
	</view>
</template>

<script>
	import {
		order_create,
		member_address,
		member_address_post,
		order_create_submit
	} from '@/api/home.js'
	export default {
		data() {
			return {
				addrlist: '',
				significance: '',
				openid: '',
				res: '',
				beizhu: '',
				orderList: '',
				addressid: '',
				remark: '',
			};
		},
		onLoad(e) {
			this.significance = e;

		},
		onShow() {
			uni.getStorage({
				key: 'openid',
				success: (res) => {
					this.openid = res.data;
					this.order_createFun();
				},
				fail: () => {
					uni.navigateTo({
						url: '/pages/login/login'
					});
				}
			});
		},
		methods: {
			async order_create_submitFun() {
				let up = {
					'id': this.res.createInfo.id,
					'fromcart': this.res.createInfo.fromcart,
					'carrierid': this.res.createInfo.storeid,
					'addressid': this.addressid,
					'remark': '',
					'fromquick': this.res.createInfo.fromquick,
					'zzzf': `0:${this.res.goodsprice}`,
					'openid': this.openid,
					'goods[0][goodsid]': this.res.createInfo.goods[0].goodsid,
					'goods[0][total]': this.res.total,
					'goods[0][optionid]': this.res.createInfo.goods[0].optionid,
					'goods[0][marketprice]': this.res.realprice,
					'goods[0][merchid]': this.res.createInfo.goods[0].merchid,
					'goods[0][cates]': '',
					'goods[0][type]': this.res.createInfo.goods[0].type
				}
				let data = await order_create_submit(up);
				if (data.status === 1) {
					uni.navigateTo({
						url: `/pages/home/shouyintai/shouyintai?orderid=${data.result.orderid}`
					})
				}
			},
			async select(id) {
				let up = {
					id,
					openid: this.openid
				}
				let data = await member_address_post(up);
				this.addressid = id;
				this.res.address = data;
				console.log(data);
				if (data !== '') {
					this.$refs.showLeft.close();
				}
			},
			async member_addressFun() {
				let data = await member_address(this.openid);
				this.orderList = data;
			},
			change(e) {
				console.log(e);
			},
			showDrawer(e) {
				this.$refs.showLeft.open();
				this.member_addressFun();
			},
			// 关闭窗口
			closeDrawer(e) {
				this.$refs.showLeft.close()
			},
			back() {
				uni.navigateBack({
					delta: 1
				})
			},
			bindTextAreaBlur(e) {
				console.log(e);
			},

			addorderFun() {
				this.closeDrawer();
				uni.navigateTo({
					url: '/pages/mine/dizhiguanli/post'
				})
			},
			async order_createFun() {
				let up = {
					id: this.significance.id,
					optionid: this.significance.id,
					total: this.significance.total,
					openid: this.openid
				}
				let data = await order_create(up);
				this.res = data;
				this.addressid = data.address.id;
				console.log(data);
			}
		}
	}
</script>

<style lang="scss">
	.confirm_an_order {
		width: 100%;
		height: 100vh;
		// padding-top: var(--status-bar-height);

		.status_bar {
			height: var(--status-bar-height);
			width: 100%;
			background-color: #fff;
		}

		.confirm_an_order_title {
			width: 100%;
			height: 88rpx;
		}

		.confirm_an_order_dizhi {
			width: 100%;
			padding: 20rpx 30rpx;

			.confirm_an_order_box_top {
				width: 100%;
				background-color: #fff;
				box-shadow: 0 0 20rpx 4rpx #ccc;
				border-radius: 20rpx;
				overflow: hidden;
				padding: 20rpx;
				// min-height: 100rpx;
				position: relative;
				display: flex;
				flex-direction: column;
				justify-content: space-between;

				.confirm_an_order_box_top_icons {
					height: 50rpx;
					position: absolute;
					top: 0;
					bottom: 0;
					right: 30rpx;
					margin: auto 0;
				}

				.confirm_an_order_box_top_DZ {
					width: 90%;
					font-size: 18px;
					font-weight: 700;
					color: #666;
					// line-height: 70rpx;

				}

				.confirm_an_order_box_top_XX {
					color: #ccc;
					font-size: 30rpx;
					padding: 10rpx 0;
				}

				.WDZ {
					width: 100%;
					height: 100%;
					display: flex;
					justify-content: center;
					align-items: center;

					.WDZ_box {
						display: flex;
						align-items: center;
						padding: 0 20rpx;
						// width: 50rpx;
						// height: 50rpx;
						// justify-content: center;
						// align-items: center;
						// border-radius: 50%;
						// margin: 0 20rpx;

						// image {
						// 	width: 100%;
						// 	height: 100%;
						// }
					}
				}
			}
		}

		.confirm_an_order_detail {
			width: 100%;
			padding: 20rpx 30rpx;

			.confirm_an_order_detail_box {
				width: 100%;
				// height: 200rpx;
				background-color: #fff;
				border-radius: 20rpx;
				box-shadow: 0 0 20rpx 4rpx #ccc;
				display: flex;
				padding: 30rpx;

				.confirm_an_order_detail_box_ {
					font-size: 28rpx;
					flex: 1;

					image {
						width: 80%;
						// height: 200rpx;
					}
				}

				.right {
					text-align: right;
				}

			}
		}

		.confirm_an_order_aggregate {
			width: 100%;
			padding: 20rpx 30rpx;

			.confirm_an_order_aggregate_box {
				width: 100%;
				// height: 200rpx;
				background-color: #fff;
				border-radius: 20rpx;
				box-shadow: 0 0 20rpx 4rpx #ccc;
				padding: 30rpx;

				.confirm_an_order_aggregate_box_ {
					display: flex;
					margin-bottom: 20rpx;

					.confirm_an_order_aggregate_box_money {
						color: #8D84FF;
					}
				}
			}

		}

		.confirm_an_order_leaveAnote {
			width: 100%;
			padding: 20rpx 30rpx;

			.confirm_an_order_leaveAnote_box {
				width: 100%;
				background-color: #fff;
				border-radius: 20rpx;
				box-shadow: 0 0 20rpx 4rpx #ccc;
				padding: 30rpx;
			}
		}


		.confirm_an_order_freight {
			width: 100%;
			padding: 20rpx 30rpx;

			.confirm_an_order_freight_box {
				width: 100%;
				background-color: #fff;
				border-radius: 20rpx;
				box-shadow: 0 0 20rpx 4rpx #ccc;
				padding: 30rpx;
				display: flex;
				justify-content: space-between;
			}
		}

		.confirm_an_order_bottom {
			width: 100%;
			height: 100rpx;
			position: fixed;
			bottom: 0;
			background-color: #fff;
			display: flex;
			align-items: center;
			justify-content: space-between;

			padding: 0rpx 40rpx;

			.confirm_an_order_bottom_an {
				width: 200rpx;
				height: 60rpx;
				line-height: 60rpx;
				text-align: center;
				background-color: #8D84FF;
				color: #fff;
				border-radius: 20rpx;
			}
		}
	}

	.close {
		width: 500rpx;
		padding: 50rpx 40rpx;
		height: 100vh;
		overflow-y: auto;

		.close_item {
			width: 100%;
			min-height: 200rpx;
			border: 1rpx solid #ccc;
			padding: 20rpx;
			border-radius: 10rpx;
			margin-bottom: 30rpx;

			.close_item_xx {
				width: 100%;
				border-bottom: 1rpx dashed #ccc;
			}

			.close_item_order {
				width: 100%;
				font-size: 26rpx;
				color: #666;
			}

		}

		.close_bottom {
			width: 100%;
			height: 100rpx;
			background-color: #8D84FF;
			color: #fff;
			line-height: 100rpx;
			text-align: center;
		}
	}
</style>